home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / pt20pc.zip / SETUP.C < prev    next >
C/C++ Source or Header  |  1991-02-04  |  23KB  |  1,005 lines

  1. #include "pt.h"
  2. #include "malloc.h"
  3. #include "string.h"
  4. #include "stdlib.h"
  5. #include "conio.h"
  6. #include "io.h"
  7.  
  8. static unsigned char *buffer, *fileBuffer;
  9. static int bufLeft = 0, bufferSize;
  10. static int lineNumber;
  11.  
  12. void pascal
  13. setGWBuffer( allocate )
  14.     int allocate;
  15. {
  16.     if( allocate ) {
  17.         bufferSize = 4096;
  18.         while( 1 ) {
  19.             fileBuffer = malloc(bufferSize);
  20.             if( fileBuffer != NULL )
  21.                 break;
  22.             bufferSize /= 2;
  23.         }
  24.     } else
  25.         free(fileBuffer);
  26. }
  27.  
  28. int pascal
  29. /* XTAG:setup */
  30. setup()
  31. {
  32.     extern unsigned char msgBuffer[];
  33.     extern unsigned char textBuffer[];
  34.     extern struct optionItem options[];
  35.     extern int debug;
  36.     extern union REGS rin, rout;
  37.     extern unsigned char textColor, selColor;
  38.     extern unsigned char bannerColor, borderColor, elevColor;
  39.     extern unsigned char topColor;
  40.     extern unsigned char windowPoints[];
  41.     extern struct colorCycle colorCycles[];
  42.     extern unsigned char maxTextCycles;
  43.     extern unsigned char maxBorderCycles;
  44.  
  45.     int i, j, fid;
  46.     register unsigned char *p;
  47.     register unsigned char *item;
  48.     int triedLocalIni;
  49.  
  50.     setGWBuffer(1);        /* allocate buffer space */
  51.  
  52.     triedLocalIni = 0;
  53.     p = findFile("pt.ini");
  54.     if( p == NULL )
  55.         return 1;
  56.     fid = openls(p, 0);
  57.  
  58. processLocalIni:
  59.     lineNumber = 1;
  60.     bufLeft = 0;
  61.     buffer = fileBuffer;
  62.  
  63.     while( 1 ) {
  64.         item = getWord(fid);
  65.         if( item == NULL )
  66.             break;
  67.         if( *item == '\0' )
  68.             continue;
  69.         p = strchr(item, '=');
  70.         if( p == NULL ) {
  71.             if( *item != '[' ) {
  72.                 cprintf(
  73.             "Missing '=' in pt%s.ini (line %d) item: \"%s\"\r\n",
  74.                     (triedLocalIni ? "local" : ""),
  75.                     lineNumber,
  76.                     item);
  77.                 goto contError;
  78.             }
  79.         } else
  80.             *p++ = '\0';
  81.         if( *item == '[' ) {
  82.             setMenu(item,  fid);
  83.             continue;
  84.         }
  85.         for(i = 0; options[i].index != OLASTITEM; i++) {
  86.             for(j = 0; options[i].name[j] != '\0'; j++) {
  87.                 if( tolower(options[i].name[j])
  88.                     != tolower(item[j]) )
  89.                     goto iContinue;
  90.             }
  91. /*************unixMode kludge -- temporary ***************/
  92. if( strncmp(item, "unix", 4) == 0 )  options[i].type = OINTEGER;
  93.             goto foundIt;
  94.         iContinue:
  95.             ;
  96.         }
  97.  
  98.         /* compute some things to check for invalid fields */
  99.         j = isdigit(*(item+1));    /* second char is a digit */
  100.         i = *(item+3) == '\0';    /* length is three */
  101.  
  102.         /* key definition? */
  103.         if( tolower(*item) == 'k' && j ) {
  104.             setKey(item, p);
  105.             continue;
  106.         }
  107.  
  108.         /* button definition? */
  109.         if( tolower(*item) == 'b' && i ) {
  110.             setButton(item, p);
  111.             continue;
  112.         }
  113.  
  114. #ifdef OVERLAYS
  115.         /* overlay command definition? */
  116.         if( tolower(*item) == 'c' && j ) {
  117.             setOverlay(item, p);
  118.             continue;
  119.         }
  120. #endif
  121.  
  122.         /* mouse motion 1 definition? */
  123.         if( tolower(*item) == 'm' && j ) {
  124.             setMMotion(1, item, p);
  125.             continue;
  126.         }
  127.  
  128.         /* mouse motion 2 definition? */
  129.         if( tolower(*item) == 'n' && j ) {
  130.             setMMotion(2, item, p);
  131.             continue;
  132.         }
  133.  
  134.         /* mouse motion quadrant definition? */
  135.         if( tolower(*item) == 'q' && j ) {
  136.             setMQuadrant(item, p);
  137.             continue;
  138.         }
  139.  
  140.         /* top line menu definition? */
  141.         if( tolower(*item) == 't' && i ) {
  142.             setTopline(item, p, 0);
  143.             continue;
  144.         }
  145.  
  146.         /* bottom line menu definition? */
  147.         if( tolower(*item) == 'l' && i ) {
  148.             setTopline(item, p, 1);
  149.             continue;
  150.         }
  151.  
  152.         /* window mouse point definition? */
  153.         if( tolower(*item) == 'w' && (*(item+4)=='\0') ) {
  154.             setWindowPoint(item, p);
  155.             continue;
  156.         }
  157.  
  158.         /* else we don't know what it is */
  159.         cprintf("Unknown option name [%s] in pt%s.ini (line %d)\r\n",
  160.             item, (triedLocalIni ? "local" : ""), lineNumber);
  161.     contError:
  162.         cprintf("Press any key to continue\r\n");
  163.         incon();
  164.         continue;
  165.     foundIt:
  166.         setOption(i, p, NULL);
  167.     }
  168.     closels(fid);
  169.     
  170.     /* see if there is a ptlocal.ini */
  171.     if( !triedLocalIni ) {
  172.         triedLocalIni = 1;
  173.         fid = openls("ptlocal.ini", 0);
  174.         if( fid >= 0 )
  175.             goto processLocalIni;
  176.     }
  177.     
  178.     /* set the first color cycle to the default colors */
  179.     colorCycles[0].textColor = textColor;
  180.     colorCycles[0].selColor = selColor;
  181.     colorCycles[0].bannerColor = bannerColor;
  182.     colorCycles[0].borderColor = borderColor;
  183.     colorCycles[0].elevColor = elevColor;
  184.     
  185.     /* set the default color modes */
  186.     if( maxTextCycles == 0 ) {
  187.         maxTextCycles = 1;
  188.         colorCycles[1].textColor = textColor;
  189.         colorCycles[1].selColor = selColor;
  190.     }
  191.     if( maxBorderCycles == 0 ) {
  192.         maxBorderCycles = 1;
  193.         colorCycles[1].bannerColor = bannerColor;
  194.         colorCycles[1].borderColor = borderColor;
  195.         colorCycles[1].elevColor = elevColor;
  196.     }
  197.  
  198.     setGWBuffer(0);        /* free buffer space */
  199.     bufLeft = 0;
  200.     return 0;
  201. }
  202.  
  203. void pascal
  204. /* XTAG:setTopline */
  205. setTopline(s, value, onBottom)
  206.     unsigned char *s, *value;
  207.     int onBottom;
  208. {
  209.     extern unsigned char toplineVector[];
  210.     extern int menuLine;
  211.     extern int firstTopMenu;
  212.     
  213.     int shifts, buttons, commandNumber, i;
  214.  
  215.     if( (onBottom && menuLine > 0)
  216.      || (!onBottom && menuLine < 0) ) {
  217.         cprintf("Mixing top and bottom menus in pt.ini\r\n");
  218.         cprintf("Press any key to continue\r\n");
  219.         incon();
  220.         onBottom = !onBottom;
  221.     }
  222.     commandNumber = atoi(value);
  223.     if( commandNumber == -1 )
  224.         commandNumber = FDONOTHING;
  225.     sscanf(&s[1], "%1x", &shifts);
  226.     sscanf(&s[2], "%1x", &buttons);
  227.     /* fix shifts so that either shift keys implies shift */
  228.     /* shift over bit1 and OR bit0 with it */
  229.     shifts = (shifts>>1) | (shifts&0x1);
  230.     i = ((shifts&0x7)<<3) + (buttons&0x7);
  231.     toplineVector[i] = (unsigned char)commandNumber;
  232.     if( onBottom )
  233.         --menuLine;
  234.     else
  235.         ++menuLine;
  236. }
  237.  
  238. void pascal
  239. /* XTAG:setButton */
  240. setButton(s, value)
  241.     unsigned char *s, *value;
  242. {
  243.     extern unsigned char buttonVector[];
  244.     
  245.     int shifts, buttons, commandNumber, i;
  246.     
  247.     commandNumber = atoi(value);
  248.     if( commandNumber == -1 )
  249.         commandNumber = FDONOTHING;
  250.     sscanf(&s[1], "%1x", &shifts);
  251.     sscanf(&s[2], "%1x", &buttons);
  252.     i = ((shifts&0x7)<<3) + (buttons&0x7);
  253.     buttonVector[i] = (unsigned char)commandNumber;
  254. }
  255.  
  256. void pascal
  257. /* XTAG:setMMotion */
  258. setMMotion(which, s, value)
  259.     int which;
  260.     unsigned char *s, *value;
  261. {
  262.     extern int mouseVec1[];
  263.     extern int mouseVec2[];
  264.     
  265.     int commandNumber, i;
  266.     
  267.     commandNumber = atoi(value);
  268.     if( commandNumber == -1 )
  269.         commandNumber = FDONOTHING;
  270.     i = *++s - '0';
  271.     if( i < 0 || i > 8 )
  272.         return;
  273.     if( which == 1 )
  274.         mouseVec1[i] = commandNumber;
  275.     else
  276.         mouseVec2[i] = commandNumber;
  277. }
  278.  
  279. void pascal
  280. /* XTAG:setWindowPoint */
  281. setWindowPoint(s, value)
  282.     register unsigned char *s;
  283.     unsigned char  *value;
  284. {
  285.     extern unsigned char msgBuffer[];
  286.     extern unsigned char windowPoints[];
  287.     
  288.     int commandNumber, n;
  289.     
  290.     commandNumber = atoi(value);
  291.     if( commandNumber == -1 )
  292.         commandNumber = FDONOTHING;
  293.     /* look at the second character of the string */
  294.     switch( *++s ) {
  295.         case 't': n = 0; break;    /* top left or right corner */
  296.         case 'b': n = 4; break;    /* bottom left or right corner */
  297.         default: n = 8; break;    /* right border */
  298.     }
  299.     ++s;    /* move to the third character in the string */
  300.     if( n == 8 ) {    /* right border */
  301.         /* skip the third character */
  302.         if( *++s == 'r' )    /* right button */
  303.             n = 9;
  304.     } else {    /* all 4 corners */
  305.         if( *s == 'r' )    /* top or bottom right corner */
  306.             n += 2;
  307.         if( *++s == 'm' )    /* middle button */
  308.             ++n;
  309.     }
  310.     windowPoints[n] = (unsigned char)commandNumber;
  311. }
  312.  
  313. void pascal
  314. /* XTAG:setMQuadrant */
  315. setMQuadrant(s, value)
  316.     unsigned char *s, *value;
  317. {
  318.     extern int quad22, quad45, quad67;
  319.     
  320.     int degrees;
  321.     
  322.     degrees = atoi(value);
  323.     if( s[1] == '1' )
  324.         quad67 = degrees;
  325.     else if( s[1] == '2' )
  326.         quad45 = degrees;
  327.     else
  328.         quad22 = degrees;
  329. }
  330.  
  331. void pascal
  332. /* XTAG:copyStringToMenuSpace */
  333. copyStringToMenuSpace(value)
  334.     unsigned char *value;
  335. {
  336.     extern unsigned char far *menuSpace;
  337.     extern unsigned char *userMessages[];
  338.     extern int nextSpace;
  339.     
  340.     while( 1 ) {
  341.         /* skip the initial " with the preincrement ++ */
  342.         menuSpace[nextSpace++] = *++value;
  343.         if( nextSpace >= MENUSPACE ) {
  344.             cprintf(userMessages[MENUSPMSG]);
  345.             break;
  346.         }
  347.         if( *value == '\0' ) {
  348.             --nextSpace;
  349.             /* eliminate the  final " (if there is one) */
  350.             if( menuSpace[nextSpace-1] == '"' )
  351.                 menuSpace[nextSpace-1] = '\0';
  352.             else
  353.                 ++nextSpace